Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow syntax extensions to return multiple items, closes #16723 #17236

Merged
merged 1 commit into from
Sep 20, 2014

Conversation

fhahn
Copy link
Contributor

@fhahn fhahn commented Sep 13, 2014

This is PR is basically the change proposed by @SimonSapin for #16723. I can also extend MacItem, as @huonw suggested, but I'm not sure how that was meant exactly. A comment for MacItem states that it's a convenience type for macros that return a single item. Should I adapt MacItem to contain a SmallVector of items instead of a single item and update the comment?

And I've two questions concerning the patch.

First, I am not sure what's the best way to duplicate the SmallVector holding the items. The way I'm doing it at the moment strikes me as suboptimal (https://github.com/fhahn/rust/compare/issue-16723-multiple-items?expand=1#diff-5100da09ad52c81568562e36ee359343R241). An additional map() call is required, because iter() returns an iterator to pointers to the elements. Is there a better way? Should I open a ticket and implement clone() for SmallVector?

And second, I had problems running the test in the test suite because it complains that there is no name MacItems in syntax::base::ext although there is. When I compile the file with

 LD_LIBRARY_PATH=x86_64-unknown-linux-gnu/stage2/lib/ 
 x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/rustc 
 -L x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/ 
 src/test/auxiliary/issue_16723_multiple_items_syntax_ext.rs 

it works. But I'm not sure which rustc binary should be used, e.g. there is on stage1 build in x86_64-unknown-linux-gnu/stage1/bin/rustc and one in x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/rustc.

@fhahn fhahn force-pushed the issue-16723-multiple-items branch 3 times, most recently from 79f55c7 to 5f0c2ea Compare September 14, 2014 13:26
impl MacResult for MacItems {
fn make_items(self: Box<MacItems>) -> Option<SmallVector<P<ast::Item>>> {
// FIXME: Implement Clone on SmallVector and use it instead of .iter().collect()
Some(self.items.as_slice().iter().map(|x| x.clone()).collect())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This takes self by value now so this could just be Some(self.items.move_iter().collect())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just Some(self.items)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that MacItems does indeed store a SmallVector this should just return Some(self.items)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes! Updated the PR.

@alexcrichton
Copy link
Member

cc @sfackler

@sfackler
Copy link
Member

You might as well remove MacItem entirely.

// option. This file may not be copied, modified, or distributed
// except according to those terms.

// aux-build:issue_16723_multiple_items_syntax_ext.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to have an // ignore-stage1.

@fhahn
Copy link
Contributor Author

fhahn commented Sep 15, 2014

Thanks for your feedback, I've updated the PR.


impl MacResult for MacItems {
fn make_items(self: Box<MacItems>) -> Option<SmallVector<P<ast::Item>>> {
// FIXME: Implement Clone on SmallVector and use it instead of .iter().collect()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This FIXME can likely be removed now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, thanks. Does it still make sense to implement Clone on SmallVector?

@@ -0,0 +1,30 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to go in run_pass_fulldeps

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that was the problem!

The test should pass now, thanks for your help and patience ;)

.

This patch replaces `MacItem` with `MacItems`.
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Sep 19, 2014
@bors bors merged commit 89b0944 into rust-lang:master Sep 20, 2014
@fhahn fhahn deleted the issue-16723-multiple-items branch September 20, 2014 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants